a = {
"zero" : 0, 
"one" : 1, 
"two" : 2, 
"three" : 3, 
"four" : 4, 
"five" : 5, 
"six" : 6,
"seven" : 7, 
"eight" : 8, 
"nine" : 9
}
b = a.keys()
c = input().split()
if len(c) > 3 or len(c) < 3:
    print("Wrong input")
    quit()
for i in range(len(c)):
    if c[i] not in b:
        print("Wrong input")
        quit()
if a[c[0]] == 0:
    print("Wrong input")
    quit()
d = a[c[0]] * 100 + a[c[1]] * 10 + a[c[2]]
c = 0
for i in range(2, int(d ** 0.5) + 1):
    if d % i == 0:
        c += 1
if c == 0:
    print(d)
    quit()
else:
    k = 5000
    e = [i for i in range(k + 1)]
    e[1] = 0
    i = 2
    while i <= k ** 0.5:
        if e[i] != 0:
            j = i**2
            while j <= k:
                e[j] = 0
                j = j + i
        i += 1
    e = [i for i in e if e[i] != 0]
    for i in range(len(e)):
        if e[i] < d and e[i + 1] > d:
            if d - e[i] <= e[i + 1] - d:
                print(e[i])
                quit()
            else:
                print(e[i + 1])
                quit()
